package com.epfresh.supplier.dialog;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.InputFilter;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.epfresh.api.utils.CashierInputFilter;
import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.Goods;

import java.math.BigDecimal;


public class InventoryEditDialog extends Dialog {

    private TextView tvSure;
    private TextView tvTitle;
    private Goods goods;

    EditText etArea;
    EditText etMarket;
    EditText etAmount;

    TextView tvUnit;


    public InventoryEditDialog(Context context,Goods goods) {
        super(context, R.style.PosDialog);
        this.goods = goods;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_inventory_edit);

        //初始化界面控件
        initView();
        //初始化界面数据
        initData();
        //初始化界面控件的事件
        initEvent();

    }

    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {

    }

    /**
     * 初始化界面控件的显示数据
     */
    private void initData() {

        etMarket.setText(goods.getUpstreamMarket());
        etAmount.setText(goods.getQuantity());
        etArea.setText(goods.getOrigin());
        tvUnit.setText(goods.getChargeUnit());

    }

    /**
     * 初始化界面控件
     */
    private void initView() {
        tvSure = (TextView) findViewById(R.id.tv_sure);

        tvTitle = (TextView) findViewById(R.id.tv_title);
        etArea = (EditText) findViewById(R.id.et_address);
        etMarket = (EditText) findViewById(R.id.et_market);
        etAmount = (EditText) findViewById(R.id.et_amount);
        tvUnit = (TextView) findViewById(R.id.tv_unit);
        etAmount.setFilters(new InputFilter[]{new CashierInputFilter()});

        tvSure.setOnClickListener(onClickListener);

        findViewById(R.id.iv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            if (onSureListener != null) {
                v.setTag(R.id.item_key_position,etAmount.getText().toString());
                v.setTag(R.id.item_key_id,etArea.getText().toString());
                v.setTag(R.id.item_key_status,etMarket.getText().toString());
                //Log.e("数量 来源地 上游",etAmount.getText().toString()+"_"+etArea.getText().toString()+etMarket.getText().toString());
                onSureListener.onClick(v);
            }
        }
    };


    View.OnClickListener onSureListener;

    public View.OnClickListener getOnSureListener() {
        return onSureListener;
    }

    public void setOnSureListener(View.OnClickListener onSureListener) {
        this.onSureListener = onSureListener;
    }

    public String getArea() {
        return etArea.getText().toString();
    }

    public String getMarket() {
        return etMarket.getText().toString();
    }

    public String getAmount() {
        return etAmount.getText().toString();
    }

    int mPosition;
    public void show(int position, Goods goods) {

        super.show();
        mPosition = position;
        this.goods = goods;
       /* tvTitle.setText(title);
        etArea.setText(s);
        etArea.setSelection(etArea.length());*/
    }
}
